package org.hot100_2;

import org.leetcode.TreeNode;

public class leetcode101 {
    public boolean isSymmetric(TreeNode root) {

        return compare(root.left,root.right);
    }
    private boolean compare(TreeNode left,TreeNode right){

        if (left==null && right==null){
            return true;
        }

        if (left==null && right!=null){
            return false;
        }

        if (left!=null && right==null){
            return false;
        }

        if (left.val!=right.val){
            return false;
        }

        boolean outSide = compare(left.left, right.right);

        boolean inSide = compare(left.right, right.left);

        return outSide && inSide;
    }

}
